require(["config"],function () {
    require(["jquery","jquery.validation","additional.method","md5"],function () {
        $(function () {




            $("#myform").validate({
                submitHandler:function(){

                    $.ajax({
                    url:"http://127.0.0.1/BangG_Net/server/register.php",
                      type:"post",
                      data:{
                        uname:$("[name='uname']").val(),
                          upwd:$("[name='upwd']").val(),
                          utel:$("[name='utel']").val(),

                      },
                      dataType:"json"

                  }).then(function (res) {
                      if (res.status==1){
                          if (confirm("注册成功!是否登录?")){
                              window.location.assign("login.html")
                          }
                      } else{
                          alert(res.msg)
                      }
                  })


                return false
                },

                rules:{
                    uname:{
                        required:true,
                        rangelength:[4,20],
                        checkname:true
                    },
                    upwd:{
                        required:true,
                        rangelength:[6,18]
                    },
                    conupwd:{

                        equalTo:"#upwd"
                    },
                    utel:{
                        required:true,
                        rangelength:[11,11]
                    }

                },
                messages:{
                    uname:{
                        required:"用户名必填",
                        rangelength:"用户名长度为4-20位",
                        checkname:"用户名以字母开头"
                    },
                    upwd:{
                        required: "密码必填",
                        rangelength:"密码长度为6-18位"
                    },
                        conupwd:{

                            equalTo:"两次密码输入不一致"
                        },
                    utel:{
                            required:"手机号码必填",
                            rangelength:"手机号码长度不合法"
                        }

                }
            })
            $.validator.addMethod("checkname",function (val) {
                return /^[a-zA-Z]+\w/.test(val);
            })
        })
    })
})